#ifndef __COMMON_H__H
#define __COMMON_H__H
// 基础库引用
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>

// 多线程开发相关库
#include <pthread.h>
#include <sys/prctl.h>

// 信号量控制按键中断
#include <execinfo.h>
#include <signal.h>

// 错误库文件
#include <errno.h>

// 网络库包应用
#include <sys/socket.h>
#include <arpa/inet.h>

//文件操作相关
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>

#include "config.h"
#ifdef PLATFORM_X86
/** 测试模式,测试本地程序 */
#define         MODULE_TEST          1
#endif

#ifdef PLATFORM_ARM
#define         MODULE_TEST          0
#endif // DEBUG

/** 返回参数 **/
#define KT_OK		 				 0
#define KT_ERROR					-1
#define KT_WARN						-2

/** 无符号字节类型表示 **/
#define uint8           unsigned char
#define uint16          unsigned short
#define uint32          unsigned int
#define uint64          unsigned long

#define START_PROGRAM                0x00             
#define END___PROGRAM                0x01             

#define START_SCAN                   0x00             
#define END___SCAN                   0x01             

typedef enum __MBOOL {
    MFAULSE = 0x00,
    MTRUE
} MBOOL;

enum Scan_Pack {
    head = 0x00,   
    scanType,   
    scanSpeed,   
    scanFreq,
    FanShapedType,
    FanShapedSector1_V,
    FanShapedSector1_S_H,
    FanShapedSector1_S_L,
    FanShapedSector1_E_H,
    FanShapedSector1_E_L,
    FanShapedSector2_V,
    FanShapedSector2_S_H,
    FanShapedSector2_S_L,
    FanShapedSector2_E_H,
    FanShapedSector2_E_L,
    FanShapedSector3_V,
    FanShapedSector3_S_H,
    FanShapedSector3_S_L,
    FanShapedSector3_E_H,
    FanShapedSector3_E_L,
};

enum Scan_Enum {                            //类型模式
    Scan_NoModule,                          //不进行扫描
    Scan_Circle = 0x01,                     //圆形扫描
    Scan_Fanshaped = 0x02,                  //扇形扫描
    Test_Startup = 0x03,                    //测试启停
    Test_Verify = 0x04,                     //测试验证
    Query_StatusTR = 0x05,                  //TR组件查询
    Gain_CtrRxModule = 0x06,                //R组件增益控制更新

    Power_TxModule = 0x07,                  //T 组件上电
    ConTrolFan = 0x08,                      //风扇转速控制

    File_Download = 0x10,                   //文件下载协议

    PinZDType = 0x9B,
};

enum Speed_Enum {
    Speed_STOP = 0x00,
    Speed_01_10,
    Speed_02_24,
    Speed_03_48,
};

enum Freq_Enum {
    Freq_9330MHZ = 33,
    Freq_9370MHZ = 37,
    Freq_9410MHZ = 41,
    Freq_9450MHZ = 45,
    Freq_9490MHZ = 49
};

enum FanShaped_Type{
    FanShaped_Period = 0x00,        //周期扫
    FanShaped_One = 0x01,           //扫一次
    FanShaped_Close = 0x02,         //发射控制关闭
    FanShaped_Open = 0x03,          //发射控制打开
};
// 接收到的参数类型
enum Para_TR {
    Para_NETWORK = 0x00,            //网络模式
    Para_TX_COMP,                   //单独发送TX组件
    Para_RX_COMP,                   //单独发送RX组件
};

enum Open_Status {
    Status_Close = 0x00,            //关闭的状态
    Status_OPEN = 0x01,             //打开状态
};

#define FS_SECTOR_VALID_NO          0x00
#define FS_SECTOR_VALID_YES         0x01

typedef struct
{
    uint8 valid;                    //0x00 无效, 0x01 有效
    uint16 start_deg;
    uint16 end_deg;
} FanShapedSector;

typedef struct
{
    uint32 scan_freq;       //当前频率
    uint32 index;           //圆扫时序号
    uint32 start_channel;    //要打开的起始通道
    uint16 scan_type;        //扫描类型
    uint8 *calib_tx_damp;          //tx校准误差数据, 衰减
    uint8 *calib_tx_phase;         //tx校准误差数据, 移相
    uint8 *calib_rx_damp;          //rx校准误差数据, 衰减
    uint8 *calib_rx_phase;         //rx校准误差数据, 移相
    uint32 deg_index;         //查找最近的波位
    double itrdeg1;          //波相1     
    double itrdeg2;          //波相2     
    double cur_deg;         //当前角度
    double diff_deg;        //幅度表
} Para_Model;


#define     U8_BIT(index)         (0x01 << index)    
void        printHex(uint8 * rbuf, int len, char *name);
void        printHex1(uint8 * rbuf, int len, int uint, char *name);
void ctrace(int signo);
/** 测试修改 .h 增量编译 */
// #define    COMPILE_INCRE

#include "logger.h"

#include "AB_para.h"
#endif // __COMMON_H__H